﻿// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

// ReSharper disable CheckNamespace
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable CommentTypo
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedParameter.Local

/*
 * Ars Magna project, http://arsmagna.ru
 */

#region Using directives

using AM.Reporting.Utils;

using System.Drawing;
using System.ComponentModel;

#endregion

#nullable enable

namespace AM.Reporting.Gauge.Radial
{
#if !DEBUG
    [DesignTimeVisible(false)]
#endif
    class RadialLabel : GaugeLabel
    {
        public RadialLabel (GaugeObject parent) : base (parent)
        {
            Parent = parent as RadialGauge;
        }

        public override void Assign (GaugeLabel src)
        {
            base.Assign (src);
        }

        public override void Serialize (ReportWriter writer, string prefix, GaugeLabel diff)
        {
            base.Serialize (writer, prefix, diff);
        }

        public override void Draw (PaintEventArgs e)
        {
            if ((Parent as RadialGauge).Type == RadialGaugeType.Circle)
            {
                base.Draw (e);
                var x = (Parent.AbsLeft + Parent.Border.Width / 2) * e.ScaleX;
                var y = (Parent.AbsTop + Parent.Border.Width / 2) * e.ScaleY;
                var dx = (Parent.Width - Parent.Border.Width) * e.ScaleX - 1;
                var dy = (Parent.Height - Parent.Border.Width) * e.ScaleY - 1;

                var lblPt = new PointF (x + dx / 2, y + dy - ((Parent.Scale as RadialScale).AvrTick.Y - y));
                var txtSize = RadialUtils.GetStringSize (e, Parent, Font, Text);
                var font = RadialUtils.GetFont (e, Parent, Font);
                Brush brush = e.Cache.GetBrush (Color);
                e.Graphics.DrawString (Text, font, brush, lblPt.X - txtSize.Width / 2, lblPt.Y - txtSize.Height / 2);
            }
        }
    }
}
